package spe.ui.treeprovider;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;

import spe.Activator;
import spe.model.notation.SPEMDiagram;
import spe.model.spem.MethodContentPackage;
import spe.model.spem.MethodLibrary;
import spe.model.spem.MethodPlugin;
import spe.model.spem.ProcessPackage;
import spe.model.spem.SPEMElement;
import spe.model.spem.SPERootElement;

/*
 * 
 */
public class MethodLibraryLabelProvider extends LabelProvider 
{	
	@Override
	public String getText(Object element)
	{
		if(IProject.class.isInstance(element))
			return ((IProject)element).getName();
		
		if(IFolder.class.isInstance(element))
			return ((IFolder)element).getName();
		
		if(IFile.class.isInstance(element))
			return ((IFile)element).getName();
		
		if(element instanceof SPEMElement)
			return ((SPEMElement)element).getName();
		
		if(SPERootElement.class.isInstance(element))
			return "spe-root";
		
		System.out.println(String.format("[MethodLibraryLabelProvider] object %s ", element.getClass()));
		
		return "static string for testing purpose";
	}
	
	public Image getImage(Object element)
	{
		if(IProject.class.isInstance(element))
			return Activator.getDefault().getImage(Activator.IMG_PROJECT);
		
		if(IFolder.class.isInstance(element))
			return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER);
		
		if(IFile.class.isInstance(element))
			return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FILE);
		
		if(SPERootElement.class.isInstance(element))
			return Activator.getImageDescriptor("icons/spe.jpg").createImage();
		
		if(SPEMDiagram.class.isInstance(element))
			return Activator.getImageDescriptor("icons/icon24/link.jpg").createImage();
		
		if(MethodLibrary.class.isInstance(element))
			return Activator.getImageDescriptor("icons/icon16/MethodLibrary.jpg").createImage();
					
		if(MethodPlugin.class.isInstance(element))
			return Activator.getImageDescriptor("icons/icon16/MethodPlugin.jpg").createImage();
		
		if(ProcessPackage.class.isInstance(element))
			return Activator.getDefault().getImage(Activator.IMG_PROCESSPACKAGE_16);
		
		if(MethodContentPackage.class.isInstance(element))
			return Activator.getDefault().getImage(Activator.IMG_METHODCONTENTPACKAGE_16);
		
		/*
		if(MethodConfiguration.class.isInstance(element))
			return Activator.getDefault().getImage(Activator.IMG_METHODCONFIG_16);
		*/
		
		return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FILE);
	}
	
}
